package com.viviet.mobileservices.dao.impl;

import java.util.List;

import org.hibernate.LockMode;

import com.viviet.mobileservices.dao.IBoCashflowDAO;
import com.viviet.mobileservices.dao.IVMTransactionDAO;
import com.viviet.mobileservices.dao.entity.VMTransaction;
import com.viviet.mobileservices.util.Logit;


/**
 * A data access object (DAO) providing persistence and search support for
 * BoCashflow entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see .VMTransactionDAO
 * @author MyEclipse Persistence Tools
 */

public class VMTransactionDAO extends BaseHelperDAO implements IVMTransactionDAO {
	private static final Logit log = Logit.getInstance(VMTransactionDAO.class);

	public void save(VMTransaction transientInstance) {
		log.debug("saving VMTransaction instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(VMTransaction persistentInstance) {
		log.debug("deleting VMTransaction instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public VMTransaction findById(java.lang.String id) {
		log.debug("getting VMTransaction instance with id: " + id);
		try {
			VMTransaction instance = (VMTransaction) getHibernateTemplate().get("BoCashflow", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding VMTransaction instance with property: " + propertyName + ", value: " + value);
		try {
			String queryString = "from VMTransaction as model where model." + propertyName + "= ?";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findAll() {
		log.debug("finding all VMTransaction instances");
		try {
			String queryString = "from VMTransaction";
			return getHibernateTemplate().find(queryString);
			// return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public VMTransaction merge(VMTransaction detachedInstance) {
		log.debug("merging VMTransaction instance");
		try {
			VMTransaction result = (VMTransaction) getHibernateTemplate().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(VMTransaction instance) {
		log.debug("attaching dirty VMTransaction instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(VMTransaction instance) {
		log.debug("attaching clean VMTransaction instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}